package top.mcwebsite.playandroid

import android.content.res.Configuration
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.ui.Modifier
import top.mcwebsite.playandroid.common.api.AppService
import top.mcwebsite.playandroid.lib.common.ext.isNightModeActiveEx
import top.mcwebsite.playandroid.lib.servicemanager.core.ServiceManager
import top.mcwebsite.playandroid.main.ui.PlayAndroidApp
import top.mcwebsite.playandroid.theme.PlayAndroidTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            PlayAndroidTheme {
                PlayAndroidApp()
            }
        }
    }

    override fun onConfigurationChanged(newConfig: Configuration) {
        super.onConfigurationChanged(newConfig)
        Log.d("MainActivity", "onConfigurationChanged")
        val appService = ServiceManager.getService<AppService>()
        if (appService.isFollowSystemTheme()) {
            appService.darkMode(newConfig.isNightModeActiveEx())
        }
    }
}

